//
//  LovePairView.m
//  LiuHeBao
//
//  Created by zr on 2018/8/23.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "LovePairView.h"

@interface LovePairView ()

@property (nonatomic, weak)UIScrollView * scrollView;
@property (nonatomic, strong)UIButton * boyXinzuoButton;
@property (nonatomic, strong)UIButton * girlXinzuoButton;
@property (nonatomic, strong)UIButton * boyShengButton;
@property (nonatomic, strong)UIButton * girlShengButton;
@property (nonatomic, strong)UIButton * boyStyleButton;
@property (nonatomic, strong)UIButton * girlStyleButton;
@property (nonatomic, strong)UILabel * boyXinzuoLabel;
@property (nonatomic, strong)UILabel * girlXinzuoLabel;
@property (nonatomic, strong)UILabel * boyShengLabel;
@property (nonatomic, strong)UILabel * girlShengLabel;
@property (nonatomic, strong)UILabel * boyStyleLabel;
@property (nonatomic, strong)UILabel * girlStyleLabel;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIImageView * oneImageView;
@property (nonatomic, strong)UIImageView * twoImageView;
@property (nonatomic, strong)UIImageView * threeImageView;


@end

@implementation LovePairView

- (void)setXinzuoBoy:(NSString *)xinzuoBoy{
    
    _xinzuoBoy = xinzuoBoy;
    
    [self.boyXinzuoButton setTitle:xinzuoBoy forState:UIControlStateNormal];
    [self.boyXinzuoButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}


- (void)setXinzuoGirl:(NSString *)xinzuoGirl{
    
    _xinzuoGirl = xinzuoGirl;
    
    [self.girlXinzuoButton setTitle:xinzuoGirl forState:UIControlStateNormal];
    [self.girlXinzuoButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}

- (void)setShengBoy:(NSString *)shengBoy{
    
    _shengBoy = shengBoy;
    
    [self.boyShengButton setTitle:shengBoy forState:UIControlStateNormal];
    [self.boyShengButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}

- (void)setShengGirl:(NSString *)shengGirl{
    
    _shengGirl = shengGirl;
    
    [self.girlShengButton setTitle:shengGirl forState:UIControlStateNormal];
    [self.girlShengButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}

- (void)setStyleBoy:(NSString *)styleBoy{
    
    _styleBoy = styleBoy;
    
    [self.boyStyleButton setTitle:styleBoy forState:UIControlStateNormal];
    [self.boyStyleButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}

- (void)setStyleGirl:(NSString *)styleGirl{
    
    _styleGirl = styleGirl;
    
    [self.girlStyleButton setTitle:styleGirl forState:UIControlStateNormal];
    [self.girlStyleButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
}



- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = WHITE_COLOR;
    self.userInteractionEnabled = YES;
    
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
    
    scrollView.bounces = NO;
//        scrollView.userInteractionEnabled = YES;
    scrollView.alwaysBounceVertical = YES;
    scrollView.alwaysBounceHorizontal = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREENH_HEIGHT + 85 * SCREENH6);
    
    self.scrollView = scrollView;
    
    [self addSubview:self.scrollView];
    
    
    self.oneImageView = [[UIImageView alloc] initWithFrame:CGRectMake(137 * SCREENH6, 20 * SCREENH6, 100 * SCREENH6, 20 * SCREENH6)];
    self.oneImageView.image = ImageNamed(@"dsfds1521");
    [self.scrollView addSubview:self.oneImageView];

    self.twoImageView = [self setupImageViewWithImage:@"dsfdsf3265"];
    [self.scrollView addSubview:self.twoImageView];
    self.threeImageView = [self setupImageViewWithImage:@"fcsdfsd52125"];
    [self.scrollView addSubview:self.threeImageView];
    
    self.oneButton = [self setupSureButton];
    [self.scrollView addSubview:self.oneButton];
    self.twoButton = [self setupSureButton];
    [self.scrollView addSubview:self.twoButton];
    self.threeButton = [self setupSureButton];
    [self.scrollView addSubview:self.threeButton];
    
    self.boyXinzuoLabel = [self setupLabelWith:@"男方星座:"];
    [self.scrollView addSubview:self.boyXinzuoLabel];
    self.girlXinzuoLabel = [self setupLabelWith:@"女方星座:"];
    [self.scrollView addSubview:self.girlXinzuoLabel];
    self.boyShengLabel = [self setupLabelWith:@"男方生肖:"];
    [self.scrollView addSubview:self.boyShengLabel];
    self.girlShengLabel = [self setupLabelWith:@"女方生肖:"];
    [self.scrollView addSubview:self.girlShengLabel];
    self.boyStyleLabel = [self setupLabelWith:@"男方血型:"];
    [self.scrollView addSubview:self.boyStyleLabel];
    self.girlStyleLabel = [self setupLabelWith:@"女方血型:"];
    [self.scrollView addSubview:self.girlStyleLabel];
    
    
    self.boyXinzuoButton = [self setupChooseButton];
    [self.scrollView addSubview:self.boyXinzuoButton];
    self.girlXinzuoButton = [self setupChooseButton];
    [self.scrollView addSubview:self.girlXinzuoButton];
    self.boyShengButton = [self setupChooseButton];
    [self.scrollView addSubview:self.boyShengButton];
    self.girlShengButton = [self setupChooseButton];
    [self.scrollView addSubview:self.girlShengButton];
    self.boyStyleButton = [self setupChooseButton];
    [self.scrollView addSubview:self.boyStyleButton];
    self.girlStyleButton = [self setupChooseButton];
    [self.scrollView addSubview:self.girlStyleButton];
}


- (void)layoutSubviews{

    [self.boyXinzuoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.oneImageView.mas_bottom).offset(30 * SCREENH6);
    }];
    
    [self.boyXinzuoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyXinzuoLabel.mas_trailing).offset(10 * SCREENH6);
        make.centerY.mas_equalTo(self.boyXinzuoLabel);
    }];
    
    [self.girlXinzuoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyXinzuoLabel);
        make.top.mas_equalTo(self.boyXinzuoLabel.mas_bottom).offset(45 * SCREENH6);
    }];
    
    [self.girlXinzuoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyXinzuoButton);
        make.centerY.mas_equalTo(self.girlXinzuoLabel);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.girlXinzuoButton.mas_bottom).offset(30 * SCREENH6);
        make.height.mas_equalTo(33 * SCREENH6);
        make.width.mas_equalTo(175 * SCREENH6);
    }];
    
    [self.twoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.height.width.mas_equalTo(self.oneImageView);
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.boyShengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.girlXinzuoLabel);
        make.top.mas_equalTo(self.twoImageView.mas_bottom).offset(30 * SCREENH6);
    }];
    
    [self.boyShengButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.girlXinzuoButton);
        make.centerY.mas_equalTo(self.boyShengLabel);
    }];
    
    [self.girlShengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyShengLabel);
        make.top.mas_equalTo(self.boyShengLabel.mas_bottom).offset(45 * SCREENH6);
    }];
    
    [self.girlShengButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyShengButton);
        make.centerY.mas_equalTo(self.girlShengLabel);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.mas_equalTo(self.oneButton);
        make.top.mas_equalTo(self.girlShengButton.mas_bottom).offset(30 * SCREENH6);
    }];
    
    [self.threeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.height.width.mas_equalTo(self.twoImageView);
        make.top.mas_equalTo(self.twoButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.boyStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.girlShengLabel);
        make.top.mas_equalTo(self.threeImageView.mas_bottom).offset(30 * SCREENH6);
    }];

    [self.boyStyleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.girlShengButton);
        make.centerY.mas_equalTo(self.boyStyleLabel);
    }];

    [self.girlStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyStyleLabel);
        make.top.mas_equalTo(self.boyStyleLabel.mas_bottom).offset(45 * SCREENH6);
    }];

    [self.girlStyleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.boyStyleButton);
        make.centerY.mas_equalTo(self.girlStyleLabel);
    }];

    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.mas_equalTo(self.twoButton);
        make.top.mas_equalTo(self.girlStyleButton.mas_bottom).offset(30 * SCREENH6);
    }];
}



- (UILabel *)setupLabelWith:(NSString *)str{
    
    UILabel * label = [UILabel new];
    
    label.textColor = BLACK_COLOR;
    label.font = [UIFont systemFontOfSize:16 * SCREENH6];
    label.text = str;
    
    return label;
}



- (UIButton *)setupSureButton{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:@"开始分析" forState:UIControlStateNormal];
    [button setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    [button setBackgroundColor:MAINCOLOR];
    [button addTarget:self action:@selector(clickStartButton:) forControlEvents:UIControlEventTouchUpInside];
    button.layer.cornerRadius = 16;
    button.layer.masksToBounds = YES;
    button.titleLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    
    return button;
}


- (UIButton *)setupChooseButton{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:@"请选择" forState:UIControlStateNormal];
    [button setTitleColor:ColorWithRGB(0xB3B3B3) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickChooseButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    return button;
}



- (UIImageView *)setupImageViewWithImage:(NSString *)str{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.image = ImageNamed(str);
    
    return imageView;
}


- (void)clickStartButton:(UIButton *)button{
    
    NSDictionary * dict;
    
    if (button == self.oneButton) {
        
        dict = @{@"type":@"3",@"a":self.boyXinzuoButton.titleLabel.text,@"b":self.girlXinzuoButton.titleLabel.text};
    }else if (button == self.twoButton){
        
        dict = @{@"type":@"4",@"a":self.boyShengButton.titleLabel.text,@"b":self.girlShengButton.titleLabel.text};
    }else if (button == self.twoButton){
        
        dict = @{@"type":@"2",@"a":self.boyStyleButton.titleLabel.text,@"b":self.girlStyleButton.titleLabel.text};
    }
   
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToPairInfoVC" object:nil userInfo:dict];
}


- (void)clickChooseButton:(UIButton *)button{

    NSString * type;
    
    if (button == self.boyXinzuoButton) {
        
        type = @"xinzuoBoy";
    }else if (button == self.girlXinzuoButton){
        
        type = @"xinzuoGril";
    }else if (button == self.boyShengButton){
        
        type = @"shengBoy";
    }else if (button == self.girlShengButton){
        
        type = @"shengGirl";
    }else if (button == self.boyStyleButton){
        
        type = @"styleBoy";
    }else if (button == self.girlStyleButton){
        
        type = @"styleGirl";
    }
    
    NSDictionary * dict = @{@"type":type};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickChooseButton" object:nil userInfo:dict];
}

@end
